﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace SS.Ynote.Classic
{
    /// <summary>
    /// Mouse Hook
    /// </summary>
    public class MouseHook : IMessageFilter
    {
        private Rectangle rect = Rectangle.Empty;
        /// <summary>
        /// Default Contructor
        /// </summary>
        public MouseHook()
        {
        }
        /// <summary>
        /// Enables Mouse
        /// </summary>
        /// <param name="rect"></param>
        public void EnableMouse(Rectangle rect)
        {
            Cursor.Clip = rect;
            Cursor.Show();
            Application.RemoveMessageFilter(this);
        }
        /// <summary>
        /// PreFilterMessage
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true;
            if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
            return false;
        }
        /// <summary>
        /// Disables Mouse
        /// </summary>
        /// <param name="f"></param>
        /// <param name="BoundRect"></param>
        private void DisableMouse(Form f, Rectangle BoundRect)
        {
            rect = Cursor.Clip;
            // Arbitrary location.
            //BoundRect = new Rectangle(50, 50, 1, 1);
            Cursor.Clip = BoundRect;
            Cursor.Hide();
            Application.AddMessageFilter(this);
        }
    }
}
